package com.example.pushdeom.Bean;

import android.content.Context;

import com.tencent.open.utils.HttpUtils;
import com.tencent.tauth.IRequestListener;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;

public class BaseApiListener implements IRequestListener {
    private Context mContext;

    public BaseApiListener() {
    }

    public BaseApiListener(Context mContext) {
        super();
        this.mContext = mContext;
    }


        @Override
        public void onComplete(JSONObject jsonObject) {
            try {
                String userName = jsonObject.getString("nickname");
                String gender = jsonObject.getString("gender");
                String userImg = jsonObject.getString("figureurl_1");
                AppSharedPreferences.setPreference(mContext,"nickname",userName);
                AppSharedPreferences.setPreference(mContext,"gender",gender);
                AppSharedPreferences.setPreference(mContext,"figureurl_1",userImg);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onIOException(IOException e) {

        }

        @Override
        public void onMalformedURLException(MalformedURLException e) {

        }

        @Override
        public void onJSONException(JSONException e) {

        }

        @Override
        public void onSocketTimeoutException(SocketTimeoutException e) {

        }

        @Override
        public void onNetworkUnavailableException(HttpUtils.NetworkUnavailableException e) {
            // 当前网络不可用时触发此异常
        }

        @Override
        public void onHttpStatusException(HttpUtils.HttpStatusException e) {
            // http请求返回码非200时触发此异常
        }

        @Override
        public void onUnknowException(Exception e) {
            // 出现未知错误时会触发此异常
        }
}
